package br.com.caiocarrara.goodbuy.model;

import java.util.ArrayList;
import java.util.List;

import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.SessionScoped;

@Component
@SessionScoped
public class Cart {
	private List<Item> items = new ArrayList<Item>();
	private Double total = 0.0;

	public List<Item> getItems() {
		return items;
	}

	public void setItems(List<Item> items) {
		this.items = items;
	}

	public Double getTotal() {
		return total;
	}

	public void setTotal(Double total) {
		this.total = total;
	}

	public void add(Item item) {
		this.items.add(item);
		total += item.getProduct().getPrice() * item.getQuantity();
	}
	
	public Integer getTotalItems() {
		return this.items.size();
	}

	public void remove(int itemIndex) {
		Item removed = this.items.remove(itemIndex);
		this.total -= removed.getItemPrice();
	}

}
